package vip.xiaonuo.facedoor.modular.device.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class DevicePublisher implements ApplicationEventPublisherAware {

    // 注入事件发布者
    private ApplicationEventPublisher applicationEventPublisher;

    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {

        this.applicationEventPublisher = applicationEventPublisher;
    }

    /**
     * 发布事件
     */
    @Async
    public void publishEvent(DeviceChangeTypeEnum changeType, DeviceSourceEnum source, Object obj) {
        applicationEventPublisher.publishEvent(new DeviceChangeEvent(changeType,source,obj));
    }

    


}
